/*
 * EARequestDelegateBean.java is part of htn-core.
 *
 * EARequestDelegateBean.java is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * EARequestDelegateBean.java is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with EARequestDelegateBean.java.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.htn;

import org.htn.AbstractEARequestDelegate;
import org.htn.rtml.RTMLHelper;
import org.htn.rtml.RTMLHelperBean;
import org.htn.rtml.RTMLMode;

/**
 * Delegates RTML documents to the relevant {@link EARequest}.
 * 
 * This class currently supports delegation to {@link EARequest}s that
 * handle the RTML modes 'inquiry', 'request', or 'resource'.
 * 
 * 
 * @author pwarner
 *
 */
public class EARequestDelegateBean extends
		AbstractEARequestDelegate<String> {

	public RTMLHelper<String> rtmlHelper = new RTMLHelperBean();
	
	public String delegate(String reference) {
		return resolveEARequest(reference).receive(reference);
	}

	private EARequest resolveEARequest(String rtml) {
		RTMLMode mode = rtmlHelper.getMode(rtml);
		EARequest agent = null;
		if (mode == RTMLMode.INQUIRY) {
			agent = super.getInquiryRequest();
		} else if (mode == RTMLMode.REQUEST) {
			agent = super.getRequestRequest();
		} else if (mode == RTMLMode.RESOURCE) {
			agent = super.getResourceRequest();
		}
		return agent;
	}

	public void setRtmlHelper(RTMLHelper<String> rtmlHelper) {
		this.rtmlHelper = rtmlHelper;
	}
	
}
